package com.qfedu.edu.iotserver.controller;

import com.qfedu.edu.iotserver.service.PayService;
import com.qfedu.edu.result.R;
import com.qfedu.edu.vo.PayVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.jdom.JDOMException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiaobobo
 * @title: PayController
 * @projectName cd-fy-2401-third-project-parent
 * @description: 支付的控制器
 * @date 2024/9/25  15:24
 */
@RequestMapping("/iotserver/pays")
@Api(description = "支付模块", tags = "支付模块")
@RestController
public class PayController {

    @Autowired
    private PayService payService;

    /**
     * 支付接口
     *
     * @param payVo
     * @return
     */
    @PostMapping("pay")
    @ApiOperation("支付接口")
    @ApiImplicitParam(name = "token", value = "用户令牌", required = true, dataType = "string", paramType = "header")
    public R pay(@RequestBody PayVo payVo, HttpServletRequest req) throws Exception {
        String urlCode = payService.pay(payVo, req);
        return R.ok().data("urlCode", urlCode);
    }


    /**
     * 微信服务器通知我们的接口
     * @param req
     * @param resp
     */
    @RequestMapping("weiXinNotify")
    @ApiOperation("微信通知本地接口")
    public void weiXinPayNotify(HttpServletRequest req, HttpServletResponse resp) throws IOException, JDOMException {
        payService.weiXinNotify(req,resp);
    }



}
